home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / utils / 2l8pe113 / bgipat.c < prev    next >
C/C++ Source or Header  |  1994-12-21  |  4KB  |  123 lines

  1. /**********************************************************************
  2. Fill-Pattern Tester 1.0
  3. Copyright (c) 1994 by Jouni Miettunen. All Rights Reserved.
  4.  
  5. Usage: tester [ pattern_file [ foreground_color background_color ]]
  6.  
  7. 0  black    4  red        8  darkgray    12 lightred
  8. 1  blue        5  magenta    9  lightblue    13 lightmagenta
  9. 2  green    6  brown    10 lightgreen    14 yellow
  10. 3  cyan        7  gray        11 lightcyan    15 white
  11.  
  12. Note: mode 640x480x16
  13.  
  14. **********************************************************************/
  15.  
  16. #include <conio.h>    /* conio */
  17. #include <stdio.h>    /* fopen,fscanf,EOF,putchar,fclose,fflush */
  18. #include <stdlib.h>    /* exit */
  19. #include <string.h>    /* strlen */
  20.  
  21. #include <graphics.h>    /* Borland BGI graphics */
  22.  
  23. #define BEEP()    putchar(7)
  24. #define ESC    0x1b
  25.  
  26. static void near init_screen    ( void                );
  27. static void near show_pattern    ( int, int, char *        );
  28. static void near exit_all    ( void                );
  29.  
  30. /* main ***************************************************************/
  31. /* the main loop ******************************************************/
  32. /**********************************************************************/
  33. int main(
  34.     int    argc,
  35.     char    **argv
  36.     )
  37. {
  38. char    p[8]    = {0},
  39.     dsc[25]    = {0};
  40. FILE    *fp;
  41. int     fg    = LIGHTBLUE,
  42.     bg    = BLUE,
  43.     off;
  44.  
  45. if ((fp=fopen(((argc==1)?"patterns.pat":argv[1]),"rb"))==NULL) exit(1);
  46. if (argc==4) { fg=atoi(argv[2])%16; bg=atoi(argv[3])%16; }
  47.  
  48. init_screen();
  49.  
  50. /* sample of expected format - TooLate Fill-Pattern Editor patterns.pat
  51.     {0x54,0x82,0x28,0x82,0x28,0x82,0x54,0x00}, // loose see-through net
  52. */
  53.  
  54. while (fscanf(fp," {%x,%x,%x,%x,%x,%x,%x,%x}, // %24[^\r\n]%*c",
  55.         &p[0],&p[1],&p[2],&p[3],&p[4],&p[5],&p[6],&p[7],dsc)!=EOF) {
  56.     show_pattern(fg,bg,p);
  57.  
  58.     /* now things get messy: try to use font with background color */
  59.     /* BGI $@%&%#* setbgcolor() resets the color number 0 == BLACK */
  60.  
  61.     setcolor(WHITE); setfillstyle(SOLID_FILL,BLACK);
  62.     off = (strlen(dsc)<<2) + 4;
  63.     bar(319-off,239-6,319+off,239+6);
  64.  
  65.     outtextxy(319,239,dsc);
  66.     BEEP(); if (getch()==ESC) break;
  67. }
  68.  
  69. fclose(fp);
  70.  
  71. exit_all(); return 0;
  72.  
  73. } /*int main*/
  74.  
  75. /* init_screen ********************************************************/
  76. /* init all stuff, draw GUI etc. **************************************/
  77. /**********************************************************************/
  78. static void near init_screen (void)
  79. {
  80. int    gdriver=VGA,    /* graphics mode VGA 640x480x16 == VGAHI */
  81.     gmode=VGAHI;    /* driver=DETECT -> mode highest available */
  82.  
  83. if (registerbgidriver(EGAVGA_driver)<0) exit(1);
  84. initgraph(&gdriver,&gmode,"");
  85. if (graphresult()!=grOk) exit(2);
  86.  
  87. settextstyle(DEFAULT_FONT,HORIZ_DIR,0);        /* default 8x8 ROM font */
  88. settextjustify(CENTER_TEXT,CENTER_TEXT);    /* default center text */
  89. cleardevice();                    /* clear graphics screen */
  90.  
  91. } /*void init_screen*/
  92.  
  93. /* show_pattern *******************************************************/
  94. /* full-screen fill-pattern *******************************************/
  95. /**********************************************************************/
  96. static void near show_pattern(
  97.     int    fgcolor,
  98.     int    bgcolor,
  99.     char    *pattern
  100.     )
  101. {
  102.     setfillstyle(USER_FILL,fgcolor);
  103.     setfillpattern(pattern,fgcolor);
  104.     setbkcolor(bgcolor);
  105.     bar(0,0,639,479);
  106.  
  107. } /*void show_pattern*/
  108.  
  109. /* exit_all ***********************************************************/
  110. /* close down all the system ******************************************/
  111. /**********************************************************************/
  112. static void near exit_all(void)
  113. {
  114.     fflush(stdin);
  115.     closegraph();
  116.     exit(0);
  117.  
  118. }/*void exit_all*/
  119.  
  120. /**********************************************************************/
  121. /*************************** A HAPPY END ******************************/
  122. /**********************************************************************/
  123.